﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Main_Data;
namespace Print_UI
{
    public partial class frmStudent_Choose : CommonForm
    {
        public frmStudent_Choose()
        {
            InitializeComponent();
        }
        public List<int> ListID { get; set; }
        public int ChooseID { get; set; }
        

        private void frmStudent_Choose_Load(object sender, EventArgs e)
        {
            try
            {
                
                LoadData();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void LoadData()
        {
            string str = string.Empty;
            foreach (var item in ListID)
                str += "," + item;
            if (str != string.Empty)
            {
                str = str.Substring(1);
                var query = Model.PRI_Template.Where("it.ID in {" + str + "}").Select(c => new { c.ID, c.TemplateName });
                cboTemplate.Properties.DataSource = query;
                cboTemplate.Properties.DisplayMember = "TemplateName";
                cboTemplate.Properties.ValueMember = "ID";
                cboTemplate.EditValue = query.FirstOrDefault().ID;
            }
        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            try
            {
                if (cboTemplate.EditValue != null)
                {
                    ChooseID = Convert.ToInt32(cboTemplate.EditValue);
                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            try
            {
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        
    }
}
